<?php

namespace home\controller;
use framework\core\Controller;
use framework\core\Factory;
class RegisterController extends Controller{
    //显示注册页面
    public function indexAction(){
        $this->smarty->left_delimiter="<{";
        $this->smarty->right_delimiter="}>";
        $this->smarty->display("login/register.html");
    }
    //提交注册表单
    public function registerAction(){
        $data['username']=$_POST['user_name'];
        $data['email']=$_POST['email'];
        $data['password']=$_POST['password'];
        $model=Factory::M('RegisterModel');
        $result=$model->checkData($data);
        if ($result){
            $res=$model->yonghu($data);
            if ($res){
                $email=$model->email($data);
                if ($email){
                    $password=$model->Password($data);
                    if ($password){
                        $register_id=$model->insert($data);
                        if ($register_id){
                            $this->jump("注册成功,即将登陆",'index.php?m=home&a=index&c=login');
                        }
                    }else{
                        $this->jump("错误原因：".$model->getError(),'index.php?m=home&a=index&c=register');
                    }
                }else{
                    $this->jump("错误原因为：".$model->getError(),'index.php?m=home&a=index&c=register');
                }
            }else{
                $this->jump("错误原因为：".$model->getError(),'index.php?m=home&a=index&c=register');
            }
        }else{
            $this->jump("错误原因为：".$model->getError(),'index.php?m=home&a=index&c=register');
        }
    }
}